//
//  SleepActivityStatusModel.swift
//  DaRings
//
//  Created by 尹琼 on 2022/11/24.
//

import UIKit
import MYModule

open class SleepActivityStatusModel: NSObject {
    
    
    /// 睡眠详情
    public var sleepingChartData: [SleepActivityStatusChartData]?
    
    /// 醒来时间
    public var fallAsleep: String = ""
    
    /// 睡着时间
    public var wakeUp: String = ""
    
    
    public var fallAsleepTitle: String {
        if fallAsleep.isEmpty {
            return ""
        }
        
        return "sleep_fail_asleep".language(with: [fallAsleep])
        
    }
    
    public var wakeUpTitle: String {
        if wakeUp.isEmpty {
            return ""
        }
        
        return "sleep_wake_up".language(with: [wakeUp])
        
        
    }

}

public struct SleepActivityStatusChartData {
    
    public enum ActivityType {
        case none
        case little
        case mid
        case fre
    }
    
    // 5分钟活动
    public var activitys: [Int]
    
    
    public var type: ActivityType
    
    public init(activitys: [Int]) {
        self.activitys = activitys
        
        let total = activitys.reduce(0, { $0 + $1 })
        
        if total == 0 {
            
            self.type = .none
            
        } else if total <= 10 {
            
            self.type = .little
            
        } else if total <= 30 {
            
            self.type = .mid
        } else {
        
            self.type = .fre
        }
        
    }
   
    
    /// view 显示高度 （根据睡眠列表最大值与当前详情酸楚比例, 1.0 版本先固定死）
    public var viewHeight: CGFloat {
        
        switch type {
            
        case .none:
            return 0
            
        case .little:
            
            return 27
            
        case .mid:
            
            return 39
            
        case .fre:
            
            return 51
            
            
        }
        
    }
    
    
    public var color: UIColor? {
        
        switch type {
            
        case .little:
            
            return UIColor.Sleep.awake
            
        case .mid:
            
            return UIColor.Sleep.rem
            
        case .fre:
            
            return UIColor.Sleep.light
            
    
        default:
            return nil
            
        }
        
    }
    
}

